<template>
  <div class="s-e-container">
    <div class="title-line">
      <div class="title-left">
        输入标题：
      </div>
      <el-input type="text" v-model="title" class="title-right"></el-input>
    </div>
    <mavon-editor style="height: 100%" v-model="content" :placeholder="`输入题解内容（支持markdown）。。。`"/>
    <div class="s-e-submit">
      <el-button @click="submit">提交</el-button>
    </div>
  </div>
</template>

<script>
import {Solution} from "../../utils/http/solutions";

export default {
  name: "EditSolution",
  data : function (){
    return{
      content : "",
      title: ""
    }
  },
  methods:{
    async submit(){
      if (this.content?.length <= 1){
        this.$error("内容不能为空")
        return
      }
      if (this.title?.length <= 1){
        this.$error("内容不能为空")
        return
      }
      var resp = await Solution.add({
        pid:parseInt(this.$route.params.proId),
        nickname:this.$store.state.userInfo.nickname,
        title:this.title,
        content:this.content
      });
      if (resp.success) {
        this.$success("提交成功")
      }else {
        this.$error("提交失败："+resp.message)
      }
    }
  }
}
</script>

<style scoped>
.title-line{
  display: flex;
  align-items: center;
  height: 70px;
  width: 100%;
  padding: 0 70px;
  box-sizing: border-box;
}
.title-right{
  width: 500px;
}
.title-left{
  width: 130px;
  font-size: 20px;
}
.s-e-container{
  height: 100%;
  display: flex;
  flex-direction: column;
}
.s-e-submit{
  margin: 30px 0;
}
</style>
